package com.bbgwap.controller;

import com.alibaba.fastjson.JSON;
import com.bbgkh.model.BaseInfo;
import com.bbgkh.service.IReportService;
import com.bbgkh.utils.UserUtils;
import com.fasterxml.jackson.databind.deser.Deserializers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by lixiang01 on 2/10/2017.
 */
@Controller
public class ReportController extends BaseController{

    @Autowired
    private IReportService reportService;


    @GetMapping(value = "report/reportPage")
    public String getReportPage(){
        return "report/report";
    }


    @GetMapping(value = "report/getReport/{timeStamp}")
    @ResponseBody
    public String newSalePage(@PathVariable String timeStamp, HttpServletRequest request, HttpServletResponse response){

        BaseInfo baseInfo;
        String uid = UserUtils.getUid(request);

        try {
            baseInfo = reportService.selectByDay(uid,timeStamp);
        } catch (Exception e) {
            logger.error("查询某一天数据出错，timestamp="+timeStamp,e);
            baseInfo = new BaseInfo("300","查询数据库失败");
        }

        return JSON.toJSONString(baseInfo);
    }
}
